// https://easings.net/
export class Algorithm {
    static easeSineIn(x: number): number {
        return 1 - Math.cos((x * Math.PI) / 2);
    }
    static easeSineOut(x: number): number {
        return Math.sin((x * Math.PI) / 2);
    }
    static easeSineInOut(x: number): number {
        return -(Math.cos(Math.PI * x) - 1) / 2;
    }
    static easeCubicIn(x: number): number {
        return Math.pow(x, 3);
    }
    static easeCubicOut(x: number): number {
        return 1 - Math.pow(1 - x, 3);
    }
    static easeCubicInOut(x: number): number {
        return x < 0.5 ? 4 * Math.pow(x, 3) : 1 - Math.pow(-2 * x + 2, 3) / 2
    }
    static easeBackIn(x: number): number {
        const c1 = 1.70158;
        const c3 = c1 + 1;

        return c3 * x * x * x - c1 * x * x;
    }
    static easeBackOut(x: number): number {
        const c1 = 1.70158;
        const c3 = c1 + 1;

        return 1 + c3 * Math.pow(x - 1, 3) + c1 * (x - 1) * (x - 1);
    }
    static easeBackInOut(x: number): number {
        const c1 = 1.70158;
        const c2 = c1 * 1.525;

        return x < 0.5
            ? (Math.pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2)) / 2
            : (Math.pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2;
    }
    static easeBounceIn(x: number): number {
        return 1 - this.easeBounceOut(1 - x);
    }
    static easeBounceOut(x: number): number {
        const n1 = 7.5625;
        const d1 = 2.75;

        if (x < 1 / d1) {
            return n1 * x * x;
        } else if (x < 2 / d1) {
            return n1 * (x -= 1.5 / d1) * x + 0.75;
        } else if (x < 2.5 / d1) {
            return n1 * (x -= 2.25 / d1) * x + 0.9375;
        } else {
            return n1 * (x -= 2.625 / d1) * x + 0.984375;
        }
    }
    static easeBounceInOut(x: number): number {
        return x < 0.5
            ? (1 - this.easeBounceOut(1 - 2 * x)) / 2
            : (1 + this.easeBounceOut(2 * x - 1)) / 2;
    }
}